|
|
|
|
|
|
|
change position either by using the Move method or by setting the Left and Top properties to new values. For example, the following two code segments accomplish the same task of changing a TextBox control's position to 100 twips from the left and 200 twips from the top of its container: |
|
|
|
|
|
|
|
|
'CODE SEGMENT 1 - Move the text box by setting its properties
txtName.Left = 100
txtName.Top = 200
'CODE SEGMENT 2 - Move the text box using the Move method
txtName.Move 100, 200 |
|
|
|
|
|
|
|
|
To see an example of the difference between using properties and methods, add code to move the command button in the previous example. With that project open, follow these steps: |
|
|
|
|
|
|
|
|
1. Open the Code window to the Form_Resize event. |
|
|
|
|
|
|
|
|
2. Add the following two lines of code to the end of the event procedure: |
|
|
|
 |
|
|
|
|
cmdWiden.Left = 100
cmdWiden.Top = Form1.ScaleHeight - cmdWiden.Height |
|
|
|
|
|
|
|
|
3. Run the program and resize the form. The code repositions the command button near the bottom of the form as you resize it, always 100 twips from the left. |
|
|
|
|
|
|
|
|
4. Stop the program and replace the two statements you just added with the following line of code: |
|
|
|
 |
|
|
|
|
cmdWiden.Move 100, Form1.ScaleHeight - cmdWiden.Height |
|
|
|
|
|
|
|
|
5. Run the program again. Notice that the code statements in both cases are slightly different, but they have the same end result. No matter whether you use the Left and Top properties or the Move method, the control itself handles the actual change in position for you. |
|
|
|
|
|
|
|
|
If you type these code segments, you may notice that the Move method has two additional arguments available. These optional arguments can change the size of the object. Using this method has the same effect as setting the Height and Width properties to new values. |
|
|
|
|
|
|
|
|
Similarly, the Show and Hide methods of a form have the same effect as changing the form's Visible property. When you invoke the form's Hide method, the effect is the same as setting its Visible property to False. (The effect, of course, is that the form disappears from the screen.) Likewise, the form's Show method produces the same effect as setting its Visible property to True. |
|
|
|
|
|
|
|
|
Form Properties Revisited |
|
|
|
|
|
|
|
|
Forms, like most of the objects used in Visual Basic, have a series of properties that control their behavior and appearance. In the earlier section "Exploring Properties," you learned about some of the properties that apply to forms. In this section, you'll learn several additional key properties of forms. You'll see how these properties can be controlled during program design and execution. Table 3.2 lists several of the key properties of a form and provides a brief |
|
|
|
|
|